<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-10-04
 * Time: 11:57
 */
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\Article as cxModel;

class Article extends Apibase{

    /**
     * 传入参数  aid
     * @return \think\response\Json 获取单条内容
     */
    public function index(){
        $getdata = request()->param();
        $cxmodel = new cxModel();
        if(empty($getdata)){
            $getlist['code'] = '0';
            $getlist['msg'] = '访问地址错误';
            return json($getlist);
        }
        $arr = $cxmodel->where('aid',$getdata['aid'])->where('status','1')->find();
        $getlist['cont'] = $cxmodel->get_onedata($arr);
        $getlist['code'] = '1';
        return json($getlist);
    }
    /**
     * 获取内容列表 请求参数 mid,fid,order,num,page,及附加参数
     * @return \think\response\Json
     */
    public function getList(){
        $getdata = request()->param();
        $cxmodel = new cxModel();
        if(empty($getdata)){
            $this->error('非法访问！');
        }
        $getlist = $cxmodel->get_list($getdata);
        $getlist['code'] = '1';
        if(empty($getlist['list'])){
            $getlist['code'] = '0';
            return json($getlist);
        }
        if(!empty($getdata['count'])){
            $add = $getdata['count'].'count';
            foreach ($getlist['list'] as $k => $v){
                if(empty($getdata['so'])){
                    $v[$add] = db($getdata['count'])->where('aid',$v['aid'])->count();
                }else{
                    $v[$add] = db($getdata['count'])->where('aid',$v['aid'])->where($getdata['so'],$v[$getdata['so']])->count();
                }
                $newlist[$k] = $v;
            }
            $getlist['list'] = $newlist;
        }
        return json($getlist);
    }



}